package com.demo.utils;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Duration;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.Period;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.Locale;
import java.util.TimeZone;

/**
 * @author wangfengchen
 * 日期操作工具类
 */
public class DateUtil {
  private static final Logger logger = LoggerFactory.getLogger(DateUtil.class);

  private DateUtil() {
  }

  public static final String DATE_FORMAT = "yyyy-MM-dd";
  public static final String DATE_MI_FORMAT = "yyyy-MM-dd HH:mm";
  public static final String DATETIME_FORMAT = "yyyy-MM-dd HH:mm:ss";
  public static final String CH_DATE_FORMAT_YMD = "yyyy年MM月dd日";
  public static final String CH_DATE_FORMAT_MD = "MM月dd日";
  public static final String DATE_DI_FORMAT = "yyyyMMddHHmmss";
  public static final long DAY_MILLI = 24 * 60 * 60 * 1000l; // 一天的MilliSecond

  /**
   * 获取当前时间的指定格式字符串
   *
   * @param format
   * @return
   */
  public static String getCurrentDate(String format) {
    return LocalDateTime.now().format(DateTimeFormatter.ofPattern(format));
  }

  /**
   * date字符串转换LocalDateTime
   *
   * @param dateStr
   * @return
   */
  public static LocalDateTime parseDateStrToLocalDateTime(String dateStr) {
    return LocalDateTime.parse(dateStr, DateTimeFormatter.ofPattern(DATETIME_FORMAT));
  }

  /**
   * LocalDateTime转换date字符串
   *
   * @param localDateTime
   * @return
   */
  public static String parseLocalDateTimeToDateStr(LocalDateTime localDateTime) {
    return localDateTime.format(DateTimeFormatter.ofPattern(DATETIME_FORMAT));
  }

  /**
   * Date转换LocalDateTime
   *
   * @param date
   * @return
   */
  public static LocalDateTime parseDateToLocalDateTime(Date date) {
    Instant instant = date.toInstant();
    return LocalDateTime.ofInstant(instant, ZoneId.systemDefault());
  }

  /**
   * LocalDateTime转换为Date
   *
   * @param localDateTime
   * @return
   */
  public static Date parseLocalDateTimeToDate(LocalDateTime localDateTime) {
    ZonedDateTime zonedDateTime = localDateTime.atZone(ZoneId.systemDefault());
    Instant instant = Instant.from(zonedDateTime);
    return Date.from(instant);
  }

  /**
   * 获取当前时间毫秒数
   *
   * @return
   */
  public static Long getCurrentMilli() {
    return Instant.now().toEpochMilli();
  }

  /**
   * 比较开始时间是否在结束时间之前
   *
   * @return
   */
  public static boolean isBefore(Date startTime, Date endTime) {
    LocalDateTime startLocalDateTime = parseDateToLocalDateTime(startTime);
    LocalDateTime endLocalDateTime = parseDateToLocalDateTime(endTime);
    return startLocalDateTime.isBefore(endLocalDateTime);
  }

  /**
   * 比较开始时间是否等于结束时间
   *
   * @return
   */
  public static boolean isEquals(Date startTime, Date endTime) {
    LocalDateTime startLocalDateTime = parseDateToLocalDateTime(startTime);
    LocalDateTime endLocalDateTime = parseDateToLocalDateTime(endTime);
    return startLocalDateTime.equals(endLocalDateTime);
  }

  /**
   * 比较开始时间是否在结束时间之后
   *
   * @return
   */
  public static boolean isAfter(Date startTime, Date endTime) {
    LocalDateTime startLocalDateTime = parseDateToLocalDateTime(startTime);
    LocalDateTime endLocalDateTime = parseDateToLocalDateTime(endTime);
    return startLocalDateTime.isAfter(endLocalDateTime);
  }

  /**
   * 比较开始时间和结束时间相差几年
   *
   * @param startTime
   * @param endTime
   * @return
   */
  public static long durationYear(Date startTime, Date endTime) {
    LocalDateTime startLocalDateTime = parseDateToLocalDateTime(startTime);
    LocalDateTime endLocalDateTime = parseDateToLocalDateTime(endTime);
    Period period = Period.between(startLocalDateTime.toLocalDate(), endLocalDateTime.toLocalDate());
    return period.getYears();
  }

  /**
   * 比较开始时间和结束时间相差几月
   *
   * @param startTime
   * @param endTime
   * @return
   */
  public static long durationMonth(Date startTime, Date endTime) {
    LocalDateTime startLocalDateTime = parseDateToLocalDateTime(startTime);
    LocalDateTime endLocalDateTime = parseDateToLocalDateTime(endTime);
    Period period = Period.between(startLocalDateTime.toLocalDate(), endLocalDateTime.toLocalDate());
    return period.toTotalMonths();
  }

  /**
   * 比较开始时间和结束时间相差几天
   *
   * @return
   */
  public static long durationDay(Date startTime, Date endTime) {
    LocalDateTime startLocalDateTime = parseDateToLocalDateTime(startTime);
    LocalDateTime endLocalDateTime = parseDateToLocalDateTime(endTime);
    return Duration.between(startLocalDateTime, endLocalDateTime).toDays();
  }

  /**
   * 比较开始时间和结束时间相差几小时
   *
   * @return
   */
  public static long durationHours(Date startTime, Date endTime) {
    LocalDateTime startLocalDateTime = parseDateToLocalDateTime(startTime);
    LocalDateTime endLocalDateTime = parseDateToLocalDateTime(endTime);
    return Duration.between(startLocalDateTime, endLocalDateTime).toHours();
  }

  /**
   * 比较开始时间和结束时间相差几分钟
   *
   * @return
   */
  public static long durationMinutes(Date startTime, Date endTime) {
    LocalDateTime startLocalDateTime = parseDateToLocalDateTime(startTime);
    LocalDateTime endLocalDateTime = parseDateToLocalDateTime(endTime);
    return Duration.between(startLocalDateTime, endLocalDateTime).toMinutes();
  }

  /**
   * 比较开始时间和结束时间相差几秒
   *
   * @return
   */
  public static long durationSeconds(Date startTime, Date endTime) {
    LocalDateTime startLocalDateTime = parseDateToLocalDateTime(startTime);
    LocalDateTime endLocalDateTime = parseDateToLocalDateTime(endTime);
    return Duration.between(startLocalDateTime, endLocalDateTime).getSeconds();
  }

  /**
   * 比较开始时间和结束时间相差几毫秒
   *
   * @return
   */
  public static long durationMillis(Date startTime, Date endTime) {
    LocalDateTime startLocalDateTime = parseDateToLocalDateTime(startTime);
    LocalDateTime endLocalDateTime = parseDateToLocalDateTime(endTime);
    return Duration.between(startLocalDateTime, endLocalDateTime).toMillis();
  }

  /**
   * 加年
   *
   * @param date
   * @param n
   * @return
   */
  public static Date plusYears(Date date, int n) {
    LocalDateTime localDateTime = parseDateToLocalDateTime(date);
    return parseLocalDateTimeToDate(localDateTime.plusYears(n));
  }

  /**
   * 减年
   *
   * @param date
   * @param n
   * @return
   */
  public static Date minusYears(Date date, int n) {
    LocalDateTime localDateTime = parseDateToLocalDateTime(date);
    return parseLocalDateTimeToDate(localDateTime.minusYears(n));
  }

  /**
   * 加月
   *
   * @param date
   * @param n
   * @return
   */
  public static Date plusMonths(Date date, int n) {
    LocalDateTime localDateTime = parseDateToLocalDateTime(date);
    return parseLocalDateTimeToDate(localDateTime.plusMonths(n));
  }

  /**
   * 减月
   *
   * @param date
   * @param n
   * @return
   */
  public static Date minusMonths(Date date, int n) {
    LocalDateTime localDateTime = parseDateToLocalDateTime(date);
    return parseLocalDateTimeToDate(localDateTime.minusMonths(n));
  }

  /**
   * 加星期
   *
   * @param date
   * @param n
   * @return
   */
  public static Date plusWeeks(Date date, int n) {
    LocalDateTime localDateTime = parseDateToLocalDateTime(date);
    return parseLocalDateTimeToDate(localDateTime.plusWeeks(n));
  }

  /**
   * 减星期
   *
   * @param date
   * @param n
   * @return
   */
  public static Date minusWeeks(Date date, int n) {
    LocalDateTime localDateTime = parseDateToLocalDateTime(date);
    return parseLocalDateTimeToDate(localDateTime.minusWeeks(n));
  }

  /**
   * 加天
   *
   * @param date
   * @param n
   * @return
   */
  public static Date plusDays(Date date, int n) {
    LocalDateTime localDateTime = parseDateToLocalDateTime(date);
    return parseLocalDateTimeToDate(localDateTime.plusDays(n));
  }

  /**
   * 减天
   *
   * @param date
   * @param n
   * @return
   */
  public static Date minusDays(Date date, int n) {
    LocalDateTime localDateTime = parseDateToLocalDateTime(date);
    return parseLocalDateTimeToDate(localDateTime.minusDays(n));
  }

  /**
   * 加小时
   *
   * @param date
   * @param n
   * @return
   */
  public static Date plusHours(Date date, int n) {
    LocalDateTime localDateTime = parseDateToLocalDateTime(date);
    return parseLocalDateTimeToDate(localDateTime.plusHours(n));
  }

  /**
   * 减小时
   *
   * @param date
   * @param n
   * @return
   */
  public static Date minusHours(Date date, int n) {
    LocalDateTime localDateTime = parseDateToLocalDateTime(date);
    return parseLocalDateTimeToDate(localDateTime.minusHours(n));
  }

  /**
   * 加分钟
   *
   * @param date
   * @param n
   * @return
   */
  public static Date plusMinutes(Date date, int n) {
    LocalDateTime localDateTime = parseDateToLocalDateTime(date);
    return parseLocalDateTimeToDate(localDateTime.plusMinutes(n));
  }

  /**
   * 减分钟
   *
   * @param date
   * @param n
   * @return
   */
  public static Date minusMinutes(Date date, int n) {
    LocalDateTime localDateTime = parseDateToLocalDateTime(date);
    return parseLocalDateTimeToDate(localDateTime.minusMinutes(n));
  }

  /**
   * 加秒
   *
   * @param date
   * @param n
   * @return
   */
  public static Date plusSeconds(Date date, int n) {
    LocalDateTime localDateTime = parseDateToLocalDateTime(date);
    return parseLocalDateTimeToDate(localDateTime.plusSeconds(n));
  }

  /**
   * 减秒
   *
   * @param date
   * @param n
   * @return
   */
  public static Date minusSeconds(Date date, int n) {
    LocalDateTime localDateTime = parseDateToLocalDateTime(date);
    return parseLocalDateTimeToDate(localDateTime.minusSeconds(n));
  }

  /**
   * 获取某一天开始时间，2021-09-13 00:00:00
   *
   * @param date
   * @return
   */
  public static Date getStartTime(Date date) {
    LocalDate localDate = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
    return parseLocalDateTimeToDate(LocalDateTime.of(localDate, LocalTime.MIN));
  }

  /**
   * 获取某一天结束时间，2021-09-13 23:59:59
   *
   * @param date
   * @return
   */
  public static Date getEndTime(Date date) {
    LocalDate localDate = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
    return parseLocalDateTimeToDate(LocalDateTime.of(localDate, LocalTime.MAX));
  }

  /**
   * 获取当前时间的指定格式
   *
   * @param format
   * @return
   */
  public static String getCurrDate(String format) {
    return dateToStr(new Date(), format);
  }

  /**
   * 时间戳转字符串--自定义格式
   *
   * @param time
   * @param format
   * @return
   */
  public static String timestampToString(Timestamp time, String format) {
    DateFormat sdf = new SimpleDateFormat(format);
    return sdf.format(time);
  }

  /**
   * yyyy-MM-dd 字符串转Date
   *
   * @param dateStr
   * @return
   */
  public static Date strToDate(String dateStr) {
    try {
      SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
      return sdf.parse(dateStr);
    } catch (Exception e) {
      logger.warn(String.valueOf(e));
    }
    return null;
  }

  /**
   * 自定义格式字符串转Date
   *
   * @param dateStr
   * @return
   */
  public static Date strToDate(String dateStr, String format) {
    try {
      SimpleDateFormat sdf = new SimpleDateFormat(format);
      return sdf.parse(dateStr);
    } catch (Exception e) {
      logger.warn(String.valueOf(e));
    }
    return null;
  }

  /**
   * Date转字符串yyyy-MM-dd HH:mm:ss
   *
   * @param date
   * @return
   */
  public static String dateToStr(Date date) {
    try {
      SimpleDateFormat sdf = new SimpleDateFormat(DATETIME_FORMAT);
      return sdf.format(date);
    } catch (Exception e) {
      logger.warn(String.valueOf(e));
    }
    return null;
  }

  /**
   * Date转自定义格式字符串
   *
   * @param date
   * @param format
   * @return
   */
  public static String dateToStr(Date date, String format) {
    try {
      SimpleDateFormat sdf = new SimpleDateFormat(format);
      return sdf.format(date);
    } catch (Exception e) {
      logger.warn(String.valueOf(e));
    }
    return null;
  }

  /**
   * 获取Date的小时数
   *
   * @param date
   * @return
   */
  public static Integer getHour(Date date) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);
    return calendar.get(Calendar.HOUR_OF_DAY);
  }

  /**
   * 获取Date的分钟数
   *
   * @param date
   * @return
   */
  public static Integer getMinute(Date date) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);
    return calendar.get(Calendar.MINUTE);
  }

  /**
   * second秒后的时间
   *
   * @param second
   * @return
   */
  public static Date getNowTimeBefore(int second) {
    Date date = new Date();
    long time = second * 1000l;//60秒
    return new Date(date.getTime() + time);
  }

  /**
   * second秒前的时间
   *
   * @param
   * @return
   */

  public static Date getNowTimeAfter(int second) {
    Date date = new Date();
    long time = second * 1000l;//60秒
    return new Date(date.getTime() - time);
  }

  /**
   * 日期后面加后缀
   * entityWrapper.between("put_on_shelves", DateUtil.getNewDateSuffix(" 00:00:00"), DateUtil.getNewDateSuffix(" 23:59:59"));
   *
   * @param suffix
   * @return
   */
  public static String getNewDateSuffix(String suffix) {
    try {
      SimpleDateFormat df = new SimpleDateFormat(DATE_FORMAT);//设置日期格式
      String data = df.format(new Date());
      data += suffix;
      return data;
    } catch (Exception e) {
      logger.warn(String.valueOf(e));
    }
    return null;
  }

  /**
   * 取得两个日期之间的日数
   *
   * @return t1到t2间的日数，如果t2 在 t1之后，返回正数，否则返回负数
   */
  public static long daysBetween(Date t1, Date t2) {
    return (t2.getTime() - t1.getTime()) / DAY_MILLI;
  }

  /**
   * 当前时间的字符串
   *
   * @param date 时间
   * @return 时间的数字字符串格式
   */
  public static String mathString(Date date) {
    SimpleDateFormat time = new SimpleDateFormat(DATE_DI_FORMAT, Locale.UK);
    return time.format(date);
  }

  /**
   * @param nowTime 新时间
   * @param oldTime 旧时间
   * @return 两个时间的相差秒数
   */

  public static int getTimeDelta(String nowTime, String oldTime) {
    SimpleDateFormat format = new SimpleDateFormat(DATETIME_FORMAT);

    Date date1;
    Date date2;
    try {
      date1 = format.parse(nowTime);
      date2 = format.parse(oldTime);
      long timeDelta = (date1.getTime() - date2.getTime()) / 1000;// 单位是秒
      return (timeDelta < 0 ? (int) timeDelta : (int) Math.abs(timeDelta));
    } catch (ParseException e) {
      logger.warn(String.valueOf(e));
      return 0;
    }

  }

  /**
   * 判断两个日期的大小
   * DATE1 > DATE2 返回1
   * DATE1 < DATE2返回-1
   * DATE1 = DATE2 返回0
   *
   * @param date1
   * @param date2
   * @return
   */
  public static int compareDate(Date date1, Date date2) {
    try {
      if (date1.getTime() > date2.getTime()) {
        logger.info("dt1 在dt2前");
        return 1;
      } else if (date1.getTime() < date2.getTime()) {
        logger.info("dt1在dt2后");
        return -1;
      } else {
        return 0;
      }
    } catch (Exception e) {
      logger.warn(String.valueOf(e));
    }
    return 0;
  }

  /**
   * 判断两个日期的大小
   * startTime > endTime 返回1
   * startTime < endTime-1
   * startTime = endTime 返回0
   *
   * @param startTime
   * @param endTime
   * @return
   */
  public static int compareDate(String startTime, String endTime) {
    DateFormat df = new SimpleDateFormat(DATETIME_FORMAT);
    try {
      Date dt1 = df.parse(startTime);
      Date dt2 = df.parse(endTime);
      return compareDate(dt1, dt2);
    } catch (Exception e) {
      logger.warn(String.valueOf(e));
      return 0;
    }
  }

  /**
   * 获取指定日期
   * 1.获取以后的日期days传正数
   * 2.获取以前的日期days传负数
   *
   * @param date
   * @param days
   * @return
   */
  public static String getSpecifiedDay(Date date, int days, String format) {
    Calendar calendar = new GregorianCalendar();
    calendar.setTime(date);
    calendar.add(Calendar.DATE, days);
    date = calendar.getTime();
    SimpleDateFormat formatter = new SimpleDateFormat(format);
    return formatter.format(date);
  }

  /**
   * 获取格林时间
   *
   * @return
   */
  public static String getGreenTime() {
    Calendar calendar = Calendar.getInstance();
    SimpleDateFormat sdf = new SimpleDateFormat("EEE d MMM yyyy HH:mm:ss 'GMT'", Locale.US);
    sdf.setTimeZone(TimeZone.getTimeZone("GMT")); // 设置时区为GMT
    return sdf.format(calendar.getTime());
  }

  /**
   * 获取当月的第一天
   */
  public static String getFirstDay() {
    SimpleDateFormat format = new SimpleDateFormat(DATE_FORMAT);
    String firstDay;
    // 获取前月的第一天
    Calendar cale = Calendar.getInstance();
    cale.add(Calendar.MONTH, 0);
    cale.set(Calendar.DAY_OF_MONTH, 1);
    firstDay = format.format(cale.getTime());
    return firstDay;
  }

  /**
   * 获取当月的最后一天
   *
   * @return
   */
  public static String getLastDay() {
    SimpleDateFormat format = new SimpleDateFormat(DATE_FORMAT);
    String lastDay;
    // 获取前月的最后一天
    Calendar cale = Calendar.getInstance();
    cale.add(Calendar.MONTH, 1);
    cale.set(Calendar.DAY_OF_MONTH, 0);
    lastDay = format.format(cale.getTime());
    return lastDay;
  }

  /**
   * 获取发布时间
   *
   * @param time
   * @return
   */
  public static String getPubTime(Date time) {
    String pubTime = "";
    long from = time.getTime();
    long to = new Date().getTime();
    int minute = (int) ((to - from) / (1000 * 60));
    if (minute < 1) {
      pubTime = "刚刚";
    } else if (minute < 60) {
      pubTime = minute + "分钟前";
    } else {
      int hours = (int) ((to - from) / (1000 * 60 * 60));
      if (hours < 24) {
        pubTime = hours + "小时前";
      } else {
        int days = (int) ((to - from) / (1000 * 60 * 60 * 24));
        pubTime = days + "天前";
      }
    }
    return pubTime;
  }

  // 获取发布时间
  public static String letterPubTime(Date time) {
    String pubTime = "";
    SimpleDateFormat sdf1 = new SimpleDateFormat(DATE_FORMAT);
    SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM");
    SimpleDateFormat sdf3 = new SimpleDateFormat("dd");
    SimpleDateFormat sdf4 = new SimpleDateFormat("yyyy");
    Date date = new Date();
    if (sdf1.format(time).equals(sdf1.format(date))) {
      SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
      pubTime = sdf.format(time);
    } else if (sdf2.format(time).equals(sdf2.format(date))) {
      Integer times = Integer.parseInt(sdf3.format(time));
      Integer dates = Integer.parseInt(sdf3.format(date));
      if (dates - times < 2) {
        pubTime = "昨天";
      } else {
        SimpleDateFormat sdf = new SimpleDateFormat("MM-dd");
        pubTime = sdf.format(time);
      }
    } else if (sdf4.format(time).equals(sdf4.format(date))) {
      SimpleDateFormat sdf = new SimpleDateFormat("MM-dd");
      pubTime = sdf.format(time);
    } else {
      pubTime = sdf1.format(time);
    }
    return pubTime;
  }

  /**
   * 日期转星期
   *
   * @param datetime
   * @return
   */
  public static String dateToWeek(String datetime) {
    SimpleDateFormat f = new SimpleDateFormat(DATE_FORMAT);
    String[] weekDays = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
    Calendar cal = Calendar.getInstance(); // 获得一个日历
    Date date;
    try {
      date = f.parse(datetime);
      cal.setTime(date);
    } catch (ParseException e) {
      logger.warn(String.valueOf(e));
    }
    int w = cal.get(Calendar.DAY_OF_WEEK) - 1; // 指示一个星期中的某天。
    if (w < 0) w = 0;
    return weekDays[w];
  }

  /**
   * 字符串月份转换成中文格式月份
   *
   * @param month 字符串月份
   * @return MM月
   */
  public static String dateToCnDate(String month) {
    StringBuilder result = new StringBuilder();
    String[] cnDate = new String[] {"〇", "一", "二", "三", "四", "五", "六", "七", "八", "九"};
    String ten = "十";
    for (int i = 0; i < month.length(); i++) {
      String str = String.valueOf(month.charAt(i));
      if (month.length() == 2) {
        if (month.equals("10")) {
          result.append(ten);
          break;
        } else {
          if (i == 0) {
            if (month.charAt(i) == '1') result.append(ten);
            else if (month.charAt(i) == '0') result.append("");
            else result.append(cnDate[Integer.parseInt(str)]).append(ten);
          }
          if (i == 1) {
            if (month.charAt(i) == '0') result.append("");
            else result.append(cnDate[Integer.parseInt(str)]);
          }
        }
      } else {
        result.append(cnDate[Integer.parseInt(str)]);
      }
    }
    result.append("月");
    return result.toString();
  }

  /**
   * 根据日期获取星座
   *
   * @param time
   * @return
   */
  public static String date2Constellation(String time) {

    Calendar c = Calendar.getInstance();
    SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
    Date date;
    try {
      date = sdf.parse(time);
      c.setTime(date);
      String constellation = date2Constellation(c);
      logger.info("星座 = {}", constellation);
      return constellation;
    } catch (ParseException e) {
      logger.warn(String.valueOf(e));
    }
    return null;
  }

  /**
   * 根据日期获取星座
   *
   * @param time
   * @return
   */
  public static String date2Constellation(Calendar time) {
    String[] constellationArray = {"水瓶座", "双鱼座", "牡羊座", "金牛座", "双子座", "巨蟹座", "狮子座", "处女座", "天秤座", "天蝎座", "射手座", "魔羯座"};
    int[] constellationEdgeDay = {20, 19, 21, 21, 21, 22, 23, 23, 23, 23, 22, 22};
    int month = time.get(Calendar.MONTH);
    int day = time.get(Calendar.DAY_OF_MONTH);
    if (day < constellationEdgeDay[month]) {
      month = month - 1;
    }
    if (month >= 0) {
      return constellationArray[month];
    }
    // default to return 双鱼座
    return constellationArray[1];
  }

  /**
   * java.time.LocalDateTime 转成 java.util.Date
   *
   * @param localDateTime
   * @return
   */
  public static Date localDateTimeToDate(LocalDateTime localDateTime) {
    ZoneId zone = ZoneId.systemDefault();
    Instant instant = localDateTime.atZone(zone).toInstant();
    return Date.from(instant);
  }

  public static LocalDateTime parseLocalDate(String str, String parsePatterns) {
    DateTimeFormatter dtf = DateTimeFormatter.ofPattern(parsePatterns);
    return LocalDateTime.parse(str, dtf);
  }

  /**
   * 给指定时间添加天数
   *
   * @param date
   * @param amount
   * @return
   */
  public static Date addDays(Date date, int amount) {
    return add(date, 5, amount);
  }

  /**
   * 给指定时间添加年数
   *
   * @param date
   * @param amount
   * @return
   */
  public static Date addYears(Date date, int amount) {
    return add(date, 1, amount);
  }

  /**
   * 给指定时间添加月数
   *
   * @param date
   * @param amount
   * @return
   */
  public static Date addMonths(Date date, int amount) {
    return add(date, 2, amount);
  }

  private static Date add(Date date, int calendarField, int amount) {
    if (date == null) {
      return null;
    } else {
      Calendar c = Calendar.getInstance();
      c.setTime(date);
      c.add(calendarField, amount);
      return c.getTime();
    }
  }

  /**
   * 给指定时间添加小时数
   *
   * @param date
   * @param hour
   * @return
   */
  public static Date addHours(Date date, int hour) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);
    cal.add(Calendar.HOUR, hour);// 24小时制
    date = cal.getTime();
    return date;
  }

  /**
   * 给指定时间添加分钟数
   *
   * @param date
   * @param minute
   * @return
   */
  public static Date addMinute(Date date, int minute) {
    SimpleDateFormat format = new SimpleDateFormat(DATETIME_FORMAT);
    //显示输入的日期
    String s = format.format(date);
    logger.info("front = {}", s);
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);
    cal.add(Calendar.MINUTE, minute);//
    date = cal.getTime();
    return date;
  }

  /**
   * 给指定时间添加秒数
   *
   * @param date
   * @param second
   * @return
   */
  public static Date addSecond(Date date, int second) {
    SimpleDateFormat format = new SimpleDateFormat(DATETIME_FORMAT);
    //显示输入的日期
    String s = format.format(date);
    logger.info("front = {}", s);
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);
    cal.add(Calendar.SECOND, second);//
    date = cal.getTime();
    return date;
  }

  /**
   * 秒转换时分秒
   *
   * @param seconds 秒为单位 比如..600秒
   * @return 比如...2小时3分钟52秒
   */
  public static String secToTime(int seconds) {
    int hour = seconds / 3600;
    int minute = (seconds - hour * 3600) / 60;
    int second = (seconds - hour * 3600 - minute * 60);

    StringBuilder sb = new StringBuilder();
    if (hour > 0) {
      sb.append(hour).append("小时");
    }
    if (minute > 0) {
      sb.append(minute).append("分");
    }
    if (minute == 0) {
      sb.append("0分");
    }
    if (second > 0) {
      sb.append(second).append("秒");
    }
    if (second == 0) {
      sb.append("0秒");
    }
    return sb.toString();
  }

  /**
   * 将int类型数字转换成时分秒毫秒的格式数据
   *
   * @param time long类型的数据
   * @return HH:mm:ss.SSS
   */
  public static String millisecondToTime(int time) {
    String timeStr = null;
    int hour = 0;
    int minute = 0;
    int second = 0;
    int millisecond = 0;
    if (time <= 0) return "00:00:00.000";
    else {
      second = time / 1000;
      minute = second / 60;
      millisecond = time % 1000;
      if (second < 60) {
        timeStr = "00:00:" + unitFormat(second) + "." + unitFormat2(millisecond);
      } else if (minute < 60) {
        second = second % 60;
        timeStr = "00:" + unitFormat(minute) + ":" + unitFormat(second) + "." + unitFormat2(millisecond);
      } else {// 数字>=3600 000的时候
        hour = minute / 60;
        minute = minute % 60;
        second = second - hour * 3600 - minute * 60;
        timeStr = unitFormat(hour) + ":" + unitFormat(minute) + ":" + unitFormat(second) + "." + unitFormat2(millisecond);
      }
    }
    return timeStr;
  }

  public static String unitFormat(int i) {// 时分秒的格式转换
    String retStr = null;
    if (i >= 0 && i < 10) retStr = "0" + Integer.toString(i);
    else retStr = "" + i;
    return retStr;
  }

  public static String unitFormat2(int i) {// 毫秒的格式转换
    String retStr = null;
    if (i >= 0 && i < 10) retStr = "00" + Integer.toString(i);
    else if (i >= 10 && i < 100) {
      retStr = "0" + Integer.toString(i);
    } else retStr = "" + i;
    return retStr;
  }

  // 获取当天的开始时间
  public static Date getDayBegin() {
    Calendar cal = new GregorianCalendar();
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    return cal.getTime();
  }

  // 获取当天的结束时间
  public static Date getDayEnd() {
    Calendar cal = new GregorianCalendar();
    cal.set(Calendar.HOUR_OF_DAY, 23);
    cal.set(Calendar.MINUTE, 59);
    cal.set(Calendar.SECOND, 59);
    return cal.getTime();
  }

  // 获取昨天的开始时间
  public static Date getBeginDayOfYesterday() {
    Calendar cal = new GregorianCalendar();
    cal.setTime(getDayBegin());
    cal.add(Calendar.DAY_OF_MONTH, -1);
    return cal.getTime();
  }

  // 获取昨天的结束时间
  public static Date getEndDayOfYesterDay() {
    Calendar cal = new GregorianCalendar();
    cal.setTime(getDayEnd());
    cal.add(Calendar.DAY_OF_MONTH, -1);
    return cal.getTime();
  }

  // 获取前天的开始时间
  public static Date getBeginDayOfQiantian() {
    Calendar cal = new GregorianCalendar();
    cal.setTime(getDayBegin());
    cal.add(Calendar.DAY_OF_MONTH, -2);
    return cal.getTime();
  }

  // 获取前天的结束时间
  public static Date getEndDayOfQiantian() {
    Calendar cal = new GregorianCalendar();
    cal.setTime(getDayEnd());
    cal.add(Calendar.DAY_OF_MONTH, -2);
    return cal.getTime();
  }

  // 获取明天的开始时间
  public static Date getBeginDayOfTomorrow() {
    Calendar cal = new GregorianCalendar();
    cal.setTime(getDayBegin());
    cal.add(Calendar.DAY_OF_MONTH, 1);
    return cal.getTime();
  }

  // 获取明天的结束时间
  public static Date getEndDayOfTomorrow() {
    Calendar cal = new GregorianCalendar();
    cal.setTime(getDayEnd());
    cal.add(Calendar.DAY_OF_MONTH, 1);
    return cal.getTime();
  }

  // 获取本周的开始时间
  @SuppressWarnings("unused")
  public static Date getBeginDayOfWeek() {
    Date date = new Date();
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);
    int dayofweek = cal.get(Calendar.DAY_OF_WEEK);
    if (dayofweek == 1) {
      dayofweek += 7;
    }
    cal.add(Calendar.DATE, 2 - dayofweek);
    return getDayStartTime(cal.getTime());
  }

  // 获取本周的结束时间
  public static Date getEndDayOfWeek() {
    Calendar cal = Calendar.getInstance();
    cal.setTime(getBeginDayOfWeek());
    cal.add(Calendar.DAY_OF_WEEK, 6);
    Date weekEndSta = cal.getTime();
    return getDayEndTime(weekEndSta);
  }

  // 获取上周的开始时间
  @SuppressWarnings("unused")
  public static Date getBeginDayOfLastWeek() {
    Date date = new Date();
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);
    int dayofweek = cal.get(Calendar.DAY_OF_WEEK);
    if (dayofweek == 1) {
      dayofweek += 7;
    }
    cal.add(Calendar.DATE, 2 - dayofweek - 7);
    return getDayStartTime(cal.getTime());
  }

  // 获取上周的结束时间
  public static Date getEndDayOfLastWeek() {
    Calendar cal = Calendar.getInstance();
    cal.setTime(getBeginDayOfLastWeek());
    cal.add(Calendar.DAY_OF_WEEK, 6);
    Date weekEndSta = cal.getTime();
    return getDayEndTime(weekEndSta);
  }

  // 获取本月的开始时间
  public static Date getBeginDayOfMonth() {
    Calendar calendar = Calendar.getInstance();
    calendar.set(getNowYear(), getNowMonth() - 1, 1);
    return getDayStartTime(calendar.getTime());
  }

  // 获取本月的结束时间
  public static Date getEndDayOfMonth() {
    Calendar calendar = Calendar.getInstance();
    calendar.set(getNowYear(), getNowMonth() - 1, 1);
    int day = calendar.getActualMaximum(Calendar.DATE);
    calendar.set(getNowYear(), getNowMonth() - 1, day);
    return getDayEndTime(calendar.getTime());
  }

  // 获取上月的开始时间
  public static Date getBeginDayOfLastMonth() {
    Calendar calendar = Calendar.getInstance();
    calendar.set(getNowYear(), getNowMonth() - 2, 1);
    return getDayStartTime(calendar.getTime());
  }

  // 获取上月的结束时间
  public static Date getEndDayOfLastMonth() {
    Calendar calendar = Calendar.getInstance();
    calendar.set(getNowYear(), getNowMonth() - 2, 1);
    int day = calendar.getActualMaximum(5);
    calendar.set(getNowYear(), getNowMonth() - 2, day);
    return getDayEndTime(calendar.getTime());
  }

  // 获取本年的开始时间
  public static Date getBeginDayOfYear() {
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.YEAR, getNowYear());
    cal.set(Calendar.MONTH, Calendar.JANUARY);
    cal.set(Calendar.DATE, 1);
    return getDayStartTime(cal.getTime());
  }

  // 获取本年的结束时间
  public static Date getEndDayOfYear() {
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.YEAR, getNowYear());
    cal.set(Calendar.MONTH, Calendar.DECEMBER);
    cal.set(Calendar.DATE, 31);
    return getDayEndTime(cal.getTime());
  }

  // 获取上年的开始时间
  public static Date getBeginDayOfLastYear() {
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.YEAR, getNowYear() - 1);
    cal.set(Calendar.MONTH, Calendar.JANUARY);
    cal.set(Calendar.DATE, 1);
    return getDayStartTime(cal.getTime());
  }

  // 获取上年的结束时间
  public static Date getEndDayOfLastYear() {
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.YEAR, getNowYear() - 1);
    cal.set(Calendar.MONTH, Calendar.DECEMBER);
    cal.set(Calendar.DATE, 31);
    return getDayEndTime(cal.getTime());
  }

  // 获取某个日期的开始时间
  public static Timestamp getDayStartTime(Date d) {
    Calendar calendar = Calendar.getInstance();
    if (null != d) calendar.setTime(d);
    calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
    calendar.set(Calendar.MILLISECOND, 0);
    return new Timestamp(calendar.getTimeInMillis());
  }

  // 获取某个日期的结束时间
  public static Timestamp getDayEndTime(Date d) {
    Calendar calendar = Calendar.getInstance();
    if (null != d) calendar.setTime(d);
    calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH), 23, 59, 59);
    calendar.set(Calendar.MILLISECOND, 999);
    return new Timestamp(calendar.getTimeInMillis());
  }

  // 获取今年是哪一年
  public static Integer getNowYear() {
    Date date = new Date();
    GregorianCalendar gc = (GregorianCalendar) Calendar.getInstance();
    gc.setTime(date);
    return gc.get(Calendar.YEAR);
  }

  // 获取本月是哪一月
  public static int getNowMonth() {
    Date date = new Date();
    GregorianCalendar gc = (GregorianCalendar) Calendar.getInstance();
    gc.setTime(date);
    return gc.get(Calendar.MONTH) + 1;
  }

  // 两个日期相减得到的天数
  public static int getDiffDays(Date beginDate, Date endDate) {
    if (beginDate == null || endDate == null) {
      throw new IllegalArgumentException("getDiffDays param is null!");
    }
    long diff = (endDate.getTime() - beginDate.getTime()) / (1000 * 60 * 60 * 24);
    return Integer.parseInt(String.valueOf(diff));
  }

  // 两个日期相减得到的毫秒数
  public static long dateDiff(Date beginDate, Date endDate) {
    long date1ms = beginDate.getTime();
    long date2ms = endDate.getTime();
    return date2ms - date1ms;
  }

  // 获取两个日期中的最大日期
  public static Date max(Date beginDate, Date endDate) {
    if (beginDate == null) {
      return endDate;
    }
    if (endDate == null) {
      return beginDate;
    }
    if (beginDate.after(endDate)) {
      return beginDate;
    }
    return endDate;
  }

  // 获取两个日期中的最小日期
  public static Date min(Date beginDate, Date endDate) {
    if (beginDate == null) {
      return endDate;
    }
    if (endDate == null) {
      return beginDate;
    }
    if (beginDate.after(endDate)) {
      return endDate;
    }
    return beginDate;
  }

  // 返回某月该季度的第一个月
  public static Date getFirstSeasonDate(Date date) {
    final int[] season = {1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4};
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);
    int sean = season[cal.get(Calendar.MONTH)];
    cal.set(Calendar.MONTH, sean * 3 - 3);
    return cal.getTime();
  }

  // 返回某个日期下几天的日期
  public static Date getNextDay(Date date, int i) {
    Calendar cal = new GregorianCalendar();
    cal.setTime(date);
    cal.set(Calendar.DATE, cal.get(Calendar.DATE) + i);
    return cal.getTime();
  }

  // 返回某个日期前几天的日期
  public static Date getFrontDay(Date date, int i) {
    Calendar cal = new GregorianCalendar();
    cal.setTime(date);
    cal.set(Calendar.DATE, cal.get(Calendar.DATE) - i);
    return cal.getTime();
  }

  // 获取某年某月到某年某月按天的切片日期集合(间隔天数的集合)
  @SuppressWarnings({"rawtypes", "unchecked"})
  public static List getTimeList(int beginYear, int beginMonth, int endYear, int endMonth, int k) {
    List list = new ArrayList();
    if (beginYear == endYear) {
      for (int j = beginMonth; j <= endMonth; j++) {
        list.add(getTimeList(beginYear, j, k));
      }
    } else {
      for (int j = beginMonth; j < 12; j++) {
        list.add(getTimeList(beginYear, j, k));
      }
      for (int i = beginYear + 1; i < endYear; i++) {
        for (int j = 0; j < 12; j++) {
          list.add(getTimeList(i, j, k));
        }
      }
      for (int j = 0; j <= endMonth; j++) {
        list.add(getTimeList(endYear, j, k));
      }
    }
    return list;
  }

  // 获取某年某月按天切片日期集合(某个月间隔多少天的日期集合)
  @SuppressWarnings({"unchecked", "rawtypes"})
  public static List getTimeList(int beginYear, int beginMonth, int k) {
    List list = new ArrayList();
    Calendar begincal = new GregorianCalendar(beginYear, beginMonth, 1);
    int max = begincal.getActualMaximum(Calendar.DATE);
    for (int i = 1; i < max; i = i + k) {
      list.add(begincal.getTime());
      begincal.add(Calendar.DATE, k);
    }
    begincal = new GregorianCalendar(beginYear, beginMonth, max);
    list.add(begincal.getTime());
    return list;
  }

  public static String getFirstDayOfMonth(String yearMonth) {

    int year = Integer.parseInt(yearMonth.split("-")[0]);  //年
    int month = Integer.parseInt(yearMonth.split("-")[1]); //月

    Calendar cal = Calendar.getInstance();

    // 设置年份
    cal.set(Calendar.YEAR, year);

    // 设置月份
    cal.set(Calendar.MONTH, month - 1);
    // 获取某月最小天数
    int firstDay = cal.getActualMinimum(Calendar.DAY_OF_MONTH);
    // 设置日历中月份的最小天数
    cal.set(Calendar.DAY_OF_MONTH, firstDay);
    // 格式化日期
    SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
    return sdf.format(cal.getTime()) + " 00:00:00";
  }

  public static String getLastDayOfMonth(String yearMonth) {
    int year = Integer.parseInt(yearMonth.split("-")[0]);  //年
    int month = Integer.parseInt(yearMonth.split("-")[1]); //月
    Calendar cal = Calendar.getInstance();
    // 设置年份
    cal.set(Calendar.YEAR, year);
    // 设置月份
    cal.set(Calendar.MONTH, month - 1);
    // 获取某月最大天数
    int lastDay = cal.getActualMaximum(Calendar.DATE);
    // 设置日历中月份的最大天数
    cal.set(Calendar.DAY_OF_MONTH, lastDay);
    // 格式化日期
    SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
    return sdf.format(cal.getTime()) + " 23:59:59";
  }

  /**
   * 字符串转日期（精确到日）
   *
   * @param str
   * @return
   * @throws Exception
   * @author zhanglw
   */
  public static Date str2Date(String str) {
    Date date = null;
    if (!StringUtils.isBlank(str)) {
      date = toDate(str, DATE_FORMAT);
    }
    return date;

  }

  /**
   * 字符串转日期（精确到日）
   *
   * @param str
   * @return
   * @author zhanglw
   */
  public static Date str2Date(String str, String format) {
    Date date = null;
    if (!StringUtils.isBlank(str)) {
      date = toDate(str, format);
    }
    return date;

  }

  /**
   * 按指定格式将字符串转换为日期对象
   *
   * @param dateStr
   * @param format
   * @return
   */
  public static Date toDate(String dateStr, String format) {
    if (StringUtils.isBlank(dateStr)) {
      logger.warn("请指定时间");
      return null;
    }
    if (StringUtils.isBlank(format)) {
      logger.warn("请指定格式");
      return null;
    }
    DateFormat df = new SimpleDateFormat(format);
    try {
      Date date = df.parse(dateStr);
      return new Date(date.getTime());
    } catch (ParseException e) {
      logger.warn("系统转换日期字符串时出错！", e);
      return null;
    }
  }

  /**
   * 时间格式化：时分秒（00:00:20）
   */
  public static String formattedTime(long second) {
    String hs;
    String ms;
    String ss;
    String formatTime;

    long h;
    long m;
    long s;
    h = second / 3600;
    m = (second % 3600) / 60;
    s = (second % 3600) % 60;
    if (h < 10) {
      hs = "0" + h;
    } else {
      hs = "" + h;
    }

    if (m < 10) {
      ms = "0" + m;
    } else {
      ms = "" + m;
    }

    if (s < 10) {
      ss = "0" + s;
    } else {
      ss = "" + s;
    }
    formatTime = hs + ":" + ms + ":" + ss;
    return formatTime;
  }

  /**
   * 交易完成时间要求是遵循 RFC3339 标准格式
   */
  public static DateTimeFormatter dateTimeFormatter() {
    return DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss+08:00").withZone(ZoneId.of("Asia/Shanghai"));
  }

  public static void main(String[] args) {

    /**
     * LocalDateTime
     */
    logger.info("获取当前时间的指定格式字符串 = {}", getCurrentDate(DATETIME_FORMAT));
    logger.info("date字符串转换LocalDateTime = {}", parseDateStrToLocalDateTime(getCurrentDate(DATETIME_FORMAT)));
    logger.info("LocalDateTime转换date字符串 = {}", parseLocalDateTimeToDateStr(LocalDateTime.now()));
    logger.info("Date转换LocalDateTime = {}", parseDateToLocalDateTime(new Date()));
    logger.info("LocalDateTime转换为Date = {}", parseLocalDateTimeToDate(LocalDateTime.now()));
    logger.info("获取当前时间毫秒数 = {}", getCurrentMilli());
    logger.info("比较开始时间是否在结束时间之前 = {}", isBefore(new Date(), plusDays(new Date(), 1)));
    logger.info("比较开始时间是否等于结束时间 = {}", isEquals(new Date(), plusDays(new Date(), 1)));
    logger.info("比较开始时间是否在结束时间之后 = {}", isAfter(new Date(), plusDays(new Date(), 1)));
    logger.info("比较开始时间和结束时间相差几年 = {}", durationYear(new Date(), plusYears(new Date(), 2)));
    logger.info("比较开始时间和结束时间相差几月 = {}", durationMonth(new Date(), plusYears(new Date(), 2)));
    logger.info("比较开始时间和结束时间相差几天 = {}", durationDay(new Date(), plusYears(new Date(), 2)));
    logger.info("比较开始时间和结束时间相差几小时 = {}", durationHours(new Date(), plusYears(new Date(), 2)));
    logger.info("比较开始时间和结束时间相差几分钟 = {}", durationMinutes(new Date(), plusYears(new Date(), 2)));
    logger.info("比较开始时间和结束时间相差几秒 = {}", durationSeconds(new Date(), plusYears(new Date(), 2)));
    logger.info("比较开始时间和结束时间相差几毫秒 = {}", durationMillis(new Date(), plusYears(new Date(), 2)));
    logger.info("获取某一天开始时间 = {}", DateUtil.dateToStr(getStartTime(new Date())));
    logger.info("获取某一天结束时间 = {}", DateUtil.dateToStr(getEndTime(new Date())));

    System.out.println("==============================================");

    logger.info("当日开始--" + DateUtil.dateToStr(getDayBegin(), "yyyy-MM-dd"));
    logger.info("当日结束--" + DateUtil.dateToStr(getDayEnd(), "yyyy-MM-dd"));

    logger.info("昨天开始--" + DateUtil.dateToStr(getBeginDayOfYesterday(), "yyyy-MM-dd"));
    logger.info("昨天结束--" + DateUtil.dateToStr(getEndDayOfYesterDay(), "yyyy-MM-dd"));

    logger.info("前天开始--" + DateUtil.dateToStr(getBeginDayOfQiantian(), "yyyy-MM-dd"));
    logger.info("前天结束--" + DateUtil.dateToStr(getEndDayOfQiantian(), "yyyy-MM-dd"));

    logger.info("本周开始--" + DateUtil.dateToStr(getBeginDayOfWeek(), "yyyy-MM-dd"));
    logger.info("本周结束--" + DateUtil.dateToStr(getEndDayOfWeek(), "yyyy-MM-dd"));

    logger.info("上周开始--" + DateUtil.dateToStr(getBeginDayOfLastWeek(), "yyyy-MM-dd"));
    logger.info("上周结束--" + DateUtil.dateToStr(getEndDayOfLastWeek(), "yyyy-MM-dd"));

    logger.info("本月开始--" + DateUtil.dateToStr(getBeginDayOfMonth(), "yyyy-MM-dd"));
    logger.info("本月结束--" + DateUtil.dateToStr(getEndDayOfMonth(), "yyyy-MM-dd"));

    logger.info("上月开始--" + DateUtil.dateToStr(getBeginDayOfLastMonth(), "yyyy-MM-dd"));
    logger.info("上月结束--" + DateUtil.dateToStr(getEndDayOfLastMonth(), "yyyy-MM-dd"));

    logger.info("本年开始--" + DateUtil.dateToStr(getBeginDayOfYear(), "yyyy-MM-dd"));
    logger.info("本年结束--" + DateUtil.dateToStr(getEndDayOfYear(), "yyyy-MM-dd"));

    logger.info("上年开始--" + DateUtil.dateToStr(getBeginDayOfLastYear(), "yyyy-MM-dd"));
    logger.info("上年结束--" + DateUtil.dateToStr(getEndDayOfLastYear(), "yyyy-MM-dd"));

    logger.info("7天之后的日期--" + getSpecifiedDay(new Date(), 7, DATETIME_FORMAT));

    logger.info("格林时间--" + DateUtil.getGreenTime());

    logger.info("过期时间===》" + DateUtil.dateTimeFormatter().format(LocalDateTime.now().plusSeconds(30)));
    logger.info("加多少秒之后的时间 = {}", dateToStr(addSecond(new Date(), 60)));
    logger.info("时间 = {}", LocalDateTime.now());

    int seconds = 3600, msec = 60;// 秒，毫秒
    System.out.println("时分秒" + secToTime(seconds));
    System.out.println(msec + "毫秒转换格式时间：\t" + millisecondToTime(msec));
    System.out.println("当前时间（时:分：秒.毫秒）\t" + new SimpleDateFormat("HH:mm:ss.SSS").format(new Date()));
    /**
     * 第一个为定时任务，根据业务需要重写TimerTask的run方法即可；
     *
     * 第二个为延时启动，单位毫秒；
     *
     * 第三个位多久运行一次，单位毫秒；
     */
    //        new Timer().schedule(new TimerTask() {
    //            @Override
    //            public void run() {
    //                try {
    //                    logger.info(DateUtil.dateTimeFormatter().format(LocalDateTime.now()));
    //                } catch (Exception e) {
    //                    e.printStackTrace();
    //                }
    //            }
    //        }, 0, 10 * 1000);

  }

}
